package chat;

public class ChatRoomManagerTest {

    public static void main(String[] args) throws InterruptedException {
        ChatRoom chatRoom = new ChatRoom();

        User user1 = new User("Alice", "password1");
        User user2 = new User("Bob", "password2");
        User user3 = new User("Charlie", "password3");

        chatRoom.registerUser(user1);
        chatRoom.registerUser(user2);
        chatRoom.registerUser(user3);

        // Simulate multiple threads for users sending messages
        Thread aliceThread = new Thread(() -> {
            try {
                Thread.sleep(1000);
                chatRoom.sendMessage(user1, "Hello, Bob!");
                Thread.sleep(2000);
                chatRoom.sendMessage(user1, "How are you doing?");
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        Thread bobThread = new Thread(() -> {
            try {
                Thread.sleep(2000);
                chatRoom.sendMessage(user2, "Hi, Alice! I'm good, thanks.");
                Thread.sleep(1000);
                chatRoom.sendMessage(user2, "What about you?");
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        Thread charlieThread = new Thread(() -> {
            try {
                Thread.sleep(3000);
                chatRoom.sendMessage(user3, "Hey everyone, I'm just joining the conversation.");
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        aliceThread.start();
        bobThread.start();
        charlieThread.start();

        aliceThread.join();
        bobThread.join();
        charlieThread.join();

        chatRoom.shutdown();
    }
}